$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + '/workflow/actFlow/getFlowPage',
        datatype: "json",
        colModel: [
            {label: '编号', name: 'id', index: 'id', width: 100},
            {label: '名称', name: 'name', index: 'name', width: 90},
            {label: 'key', name: 'key', index: 'key', width: 90},
            {label: '版本', name: 'version', index: 'version', width: 80},
            {label: '部署id', name: 'deploymentId', index: 'deploymentId', width: 80},
            {
                label: '操作', width: 80, formatter: function (value, options, row) {
                return '<a class="btn btn-modify"  onclick=vm.getDeployInfo(\"' + row.id + '\") style="display: inline;">启动</a>' +
                    '&nbsp;&nbsp;&nbsp;<a class="btn btn-delete"  onclick=vm.del(\"' + row.key + '\") style="display: inline;">删除</a>'
            }
            }
        ],
        viewrecords: true,
        height: 365,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {},
        showList: true,
        title: null,
        model: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.model = {};
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        save: function (event) {
            var url = "workflow/actModel/createActModel";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                // url: url,
                contentType: "application/json",
                data: JSON.stringify(vm.model),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (key) {
            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "workflow/actFlow/delteProcessDefinitionByKey/" + key,
                    contentType: "application/json",
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getDeployInfo: function (id) {
            var storage = window.localStorage;
            storage.setItem("deployId", id);
            window.location.href = "deployinfo.html";
        },
        getInfo: function (id) {
            $.get(baseURL + "legalprovisions/info/" + id, function (r) {
                vm.legalProvisions = r.legalProvisions;
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page,
                postData: {'queryname': vm.q.name}
            }).trigger("reloadGrid");
        }
    }
});